//
//  UINavigationBar+LH.m
//  ScrollviewDemo
//
//  Created by zhouLiHuan on 2017/1/4.
//  Copyright © 2017年 zhouLiHuan. All rights reserved.
//

#import "UINavigationBar+LH.h"

#import <objc/runtime.h>


@implementation UINavigationBar (LH)

static char overlayKey;

- (UIView *)overlay{
    
    return objc_getAssociatedObject(self, &overlayKey);
}

- (void)setOverlay:(UIView *)overlay{
    objc_setAssociatedObject(self, &overlayKey, overlay, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}
- (void)lhSetBackgroundColor:(UIColor *)backgroundColor{
    
    if (!self.overlay) {
        [self setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault];
        self.overlay  = [[UIView alloc] initWithFrame:CGRectMake(0, -20, [UIScreen mainScreen].bounds.size.width, CGRectGetHeight(self.bounds)+20)];
        self.overlay.userInteractionEnabled = NO;
        self.overlay.autoresizingMask = UIViewAutoresizingFlexibleWidth;
        [self insertSubview:self.overlay atIndex:0];
    }
    self.overlay.backgroundColor = backgroundColor;
}

- (void)lhReset{
    
    [self setBackgroundImage:nil forBarMetrics:UIBarMetricsDefault];
    [self.overlay removeFromSuperview];
    
    self.overlay = nil;
}
@end
